import { http } from "@/utils/http";

import { whReqBaseUrl as VITE_REQUEST_BASE_SAAS_API } from "@/api/common";

type pageType = {
  skip: number;
  limit: number;
};

type queryUsersType = {
  loginName?: string;
  skip: number;
  limit: number;
};
/**
 * 查询用户
 */
export function getUsersApi(data: queryUsersType) {
  return http.get<any>(`${VITE_REQUEST_BASE_SAAS_API}/users`, {
    params: {
      ...data
    }
  });
}

type newUserDataType = {
  userId: string;
  data: {
    sysUserId?: string;
    name: string;
    loginName: string;
    password: string;
    isDisabled: 0 | 1; //是否禁用,0=正常,1=禁用
    areaRanges: Array<//负责区域
    {
      type: 1 | 2 | 3 | 4; //类型 1=全国 2=省 3=市 4=区
      provinceId: string;
      cityId: string;
      areaId: string;
    }>;
  };
};
// 新增和编辑用户
export function createUsers(newUserData) {
  return http.postForm<any>(`${VITE_REQUEST_BASE_SAAS_API}/users`, {
    ...newUserData
  });
}

/**
 * 查询地区目标
 */
export function getDistrictGoals(data: pageType) {
  return http.get<any>(`${VITE_REQUEST_BASE_SAAS_API}/cfg/getDistrictGoals`, {
    params: {
      ...data
    }
  });
}

type creataGolasType = {
  userId: string;
  data: {
    id?: string;
    provinceId: string;
    cityId: string;
    areaId: string;
    healthEducationCount: number; //健康教育目标人数
    medicationManagementCount: number; //用药管理目标人数
    illnessInsuranceCount: number; //大病保障目
  };
};
// 新增和编辑用户
export function createDistrictGoals(newData) {
  return http.postForm<any>(
    `${VITE_REQUEST_BASE_SAAS_API}/cfg/editDistrictGoals`,
    {
      ...newData
    }
  );
}

// 删除地区目标
export function deleteDistrictGoals(id: string, data) {
  return http.postForm<any>(
    `${VITE_REQUEST_BASE_SAAS_API}/cfg/deleteDistrictGoals/${id}`,
    {
      ...data
    }
  );
}
// 获取内容列表
export function getContentManagements(
  data: { type?: 1 | 2; search: string } & pageType
) {
  return http.get<any>(`${VITE_REQUEST_BASE_SAAS_API}/contentManagements`, {
    params: {
      ...data
    }
  });
}

// 获取内容详情

export function getContentManagementDetail(id) {
  return http.get<any>(
    `${VITE_REQUEST_BASE_SAAS_API}/contentManagements/${id}`,
    {
      params: {}
    }
  );
}

// 新增和编辑内容
export function createContentMangements(newData) {
  return http.postForm<any>(
    `${VITE_REQUEST_BASE_SAAS_API}/contentManagements`,
    {
      ...newData
    }
  );
}

// 删除内容
export function deleteContentManagements(id: string, data) {
  return http.postForm<any>(
    `${VITE_REQUEST_BASE_SAAS_API}/contentManagements/${id}/delete `,
    {
      ...data
    }
  );
}

// 查询用户配置
export function getUserConfiguration(id) {
  return http.get<{
    smsMargin: number;
    signs: string;
  }>(`${VITE_REQUEST_BASE_SAAS_API}/users/configuration`, {
    params: {
      userId: id
    }
  });
}
